package InputStreamAndOutputStream;

import java.io.*;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.List;

/**
 * 两个转换流复制文件
 */
public class OutputStreamWriterTest {
    public static void main(String[] args) {
        BufferedWriter bw=null;
        BufferedReader br=null;
        List<String> list=new ArrayList<>();
        try{
            br=new BufferedReader(new InputStreamReader(new FileInputStream("C:\\Users\\Wang Huifang\\Desktop\\1.txt"),"UTF-8"));
            String temp;
            while((temp=br.readLine())!=null){
                list.add(temp);
            }
            bw=new BufferedWriter(new OutputStreamWriter(new FileOutputStream(""),"UTF-8"));
            for(int i=list.size()-1;i>=0;i--){
                bw.write(list.get(i));
                bw.newLine();//底层写入一个换行符
            }
            bw.flush();
        }catch(IOException e){
            e.printStackTrace();
        }finally {
            try{
                if(bw!=null){
                    bw.close();
                }
                if(br!=null){
                    br.close();
                }
            }catch(IOException e){
                e.printStackTrace();
            }
        }
    }
}
